package be.ac.ua.ecampus.uacmat.entity;

import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;

import be.ac.ua.ecampus.uacmat.QueryHandler;

public class Program extends Entity {
    private String fTraining_id;
    private Training fTraining;
    private Collection<Course> fCourses;
    
    public Program(String id, String description, String training_id) throws SQLException {
            super("program", id, description);
            fCourses = new HashSet<Course>();
    }
       
    public Training getTraining() throws SQLException {
    	if (fTraining == null) {
    		QueryHandler queryHandler = new QueryHandler();
    		fTraining = queryHandler.getTraining(fTraining_id);
    	}
    	if (fTraining == null) {
    		fTraining = new Training("", "No training available.");
    	}
    	return fTraining;
    }
    
    public Collection<Course> getCourses() throws SQLException {
    	if (fCourses.isEmpty()) {
    		QueryHandler queryHandler = new QueryHandler();
            fCourses = queryHandler.getCoursesForProgram(this.fId);
    	}
    	return fCourses;
    }
}